home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / Library / Grant's CGI Framework / Grant's CGI Framework / grantscgi / Util / TCPUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-20  |  4.5 KB  |  234 lines

  1. /*****
  2.  *
  3.  *    TCPUtil.c
  4.  *
  5.  *    This is a support file for "Grant's CGI Framework".
  6.  *    Please see the license agreement that accompanies the distribution package
  7.  *    for licensing details.
  8.  *
  9.  *    Copyright ©1996 by Grant Neufeld
  10.  *    grant@acm.com
  11.  *    http://arpp.carleton.ca/cgi/framework/
  12.  *
  13.  *****/
  14.  
  15. #include "MyConfiguration.h"
  16. #if kCompileWithTCPCode
  17.  
  18. #if kCompilingForWSAPI
  19. #include <WSAPI.h>
  20. #endif
  21.  
  22. #include "CGI.h"
  23. #include "DebugUtil.h"
  24. #include "MemoryUtil.h"
  25.  
  26. #include "TCPUtil.h"
  27.  
  28.  
  29. /***  LOCAL VARIABLES  ***/
  30.  
  31. /***  LOCAL CONSTANTS  ***/
  32.  
  33. /***  LOCAL PROTOTYPES  ***/
  34.  
  35. /***  FUNCTIONS  ***/
  36.  
  37. /*  */
  38. p_export
  39. SInt32
  40. TCPOpenClientStream ( CGIHdl theCGIHdl, UInt32 serverIP, UInt16 serverPort )
  41. {
  42.     #if kCompilingForWSAPI
  43.     
  44.     WSAPI_ErrorCode        theErr;
  45.     SInt8                savedHandleState;
  46.     
  47.     my_assert ( theCGIHdl != NULL, "\pTCPOpenClientStream: theCGIHdl is NULL" );
  48.     
  49.     savedHandleState = HGetState ( (Handle)theCGIHdl );
  50.     HLock ( (Handle)theCGIHdl );
  51.     
  52.     theErr = WSAPI_OpenStream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream), serverIP, serverPort );
  53.     
  54.     HSetState ( (Handle)theCGIHdl, savedHandleState );
  55.     
  56.     #else
  57.     
  58.     #pragma unused(theCGIHdl,serverIP,serverPort)
  59.     
  60.     OSErr    theErr;
  61.     
  62.     theErr = 1;
  63.     
  64.     #endif
  65.     
  66.     return theErr;
  67. } /* TCPOpenClientStream */
  68.  
  69.  
  70. /*  */
  71. p_export
  72. SInt32
  73. TCPCloseClientStream ( CGIHdl theCGIHdl, UInt32 serverIP, UInt16 serverPort )
  74. {
  75.     #if kCompilingForWSAPI
  76.     
  77.     WSAPI_ErrorCode        theErr;
  78.     SInt8                savedHandleState;
  79.     
  80.     my_assert ( theCGIHdl != NULL, "\pTCPCloseClientStream: theCGIHdl is NULL" );
  81.     
  82.     savedHandleState = HGetState ( (Handle)theCGIHdl );
  83.     HLock ( (Handle)theCGIHdl );
  84.     
  85.     theErr = WSAPI_CloseStream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream) );
  86.     
  87.     HSetState ( (Handle)theCGIHdl, savedHandleState );
  88.     
  89.     #else
  90.     
  91.     #pragma unused(theCGIHdl,serverIP,serverPort)
  92.     
  93.     OSErr    theErr;
  94.     
  95.     theErr = 1;
  96.     
  97.     #endif
  98.     
  99.     return theErr;
  100. } /* TCPCloseClientStream */
  101.  
  102.  
  103. /*  */
  104. p_export
  105. SInt32
  106. TCPReadFromClientStream ( CGIHdl theCGIHdl, void *outData, UInt32 *outDataSize )
  107. {
  108.     #if kCompilingForWSAPI
  109.     
  110.     WSAPI_ErrorCode        theErr;
  111.     SInt8                savedHandleState;
  112.     
  113.     my_assert ( theCGIHdl != NULL, "\pTCPReadFromClientStream: theCGIHdl is NULL" );
  114.     
  115.     savedHandleState = HGetState ( (Handle)theCGIHdl );
  116.     HLock ( (Handle)theCGIHdl );
  117.     
  118.     theErr = WSAPI_ReadStream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream), outData, outDataSize );
  119.     
  120.     HSetState ( (Handle)theCGIHdl, savedHandleState );
  121.     
  122.     #else
  123.     
  124.     #pragma unused(theCGIHdl,outData,outDataSize)
  125.     
  126.     OSErr    theErr;
  127.     
  128.     theErr = 1;    
  129.     
  130.     #endif
  131.     
  132.     return theErr;
  133. } /* TCPReadFromClientStream */
  134.  
  135.  
  136. /*  */
  137. p_export
  138. SInt32
  139. TCPWriteToClientStream ( CGIHdl theCGIHdl, void *dataToSend, UInt32 dataLength )
  140. {
  141.     #if kCompilingForWSAPI
  142.     
  143.     WSAPI_ErrorCode        theErr;
  144.     SInt8                savedHandleState;
  145.     
  146.     my_assert ( theCGIHdl != NULL, "\pTCPWriteToClientStream: theCGIHdl is NULL" );
  147.     
  148.     savedHandleState = HGetState ( (Handle)theCGIHdl );
  149.     HLock ( (Handle)theCGIHdl );
  150.     
  151.     theErr = WSAPI_WriteStream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream), dataToSend, dataLength );
  152.     
  153.     HSetState ( (Handle)theCGIHdl, savedHandleState );
  154.     
  155.     #else
  156.     
  157.     #pragma unused(theCGIHdl,dataToSend,dataLength)
  158.     
  159.     OSErr    theErr;
  160.     
  161.     theErr = 1;
  162.     
  163.     #endif
  164.     
  165.     return theErr;
  166. } /* TCPWriteToClientStream */
  167.  
  168.  
  169. /*  */
  170. p_export
  171. SInt32
  172. TCPClientStreamStatus ( CGIHdl theCGIHdl, UInt32 serverIP, TCPStreamStatus *outStatus, UInt32 *bytesUnread )
  173. {
  174.     #if kCompilingForWSAPI
  175.     
  176.     WSAPI_ErrorCode        theErr;
  177.     SInt8                savedHandleState;
  178.     WSAPI_ConnectionStatus    theStatus;
  179.     
  180.     my_assert ( theCGIHdl != NULL, "\pTCPClientStreamStatus: theCGIHdl is NULL" );
  181.     
  182.     savedHandleState = HGetState ( (Handle)theCGIHdl );
  183.     HLock ( (Handle)theCGIHdl );
  184.     
  185.     theErr = WSAPI_Stream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream), outStatus, bytesUnread );
  186.     
  187.     HSetState ( (Handle)theCGIHdl, savedHandleState );
  188.     
  189.     #else
  190.     
  191.     #pragma unused(theCGIHdl,serverIP,outStatus,bytesUnread)
  192.     
  193.     OSErr    theErr;
  194.     
  195.     theErr = 1;
  196.     
  197.     #endif
  198.     
  199.     return theErr;
  200. } /* TCPClientStreamStatus */
  201.  
  202.  
  203. /*  */
  204. p_export
  205. SInt32
  206. TCPNameToIPAddress ( CGIHdl theCGIHdl, char *name, UInt32 *ipAddress )
  207. {
  208.     #if kCompilingForWSAPI
  209.     
  210.     WSAPI_ErrorCode        theErr;
  211.     
  212.     my_assert ( theCGIHdl != NULL, "\pTCPNameToIPAddress: theCGIHdl is NULL" );
  213.     my_assert ( name != NULL, "\pTCPNameToIPAddress: name is NULL" );
  214.     my_assert ( ipAddress != NULL, "\pTCPNameToIPAddress: ipAddress is NULL" );
  215.     
  216.     theErr = WSAPI_IPNameToAddr ( (*theCGIHdl)->wsapi, name, ipAddress );
  217.     
  218.     #else
  219.     
  220.     #pragma unused(theCGIHdl,name,ipAddress)
  221.     
  222.     OSErr    theErr;
  223.     
  224.     theErr = 1;
  225.     
  226.     #endif
  227.     
  228.     return theErr;
  229. } /* TCPNameToIPAddress */
  230.  
  231.  
  232. #endif /* kCompileWithTCPCode */
  233. /***  EOF  ***/
  234.